package com.itheima.d6_lambda;

import java.util.Arrays;
import java.util.Comparator;

public class LambdaDemo2 {
    public static void main(String[] args) {
        Student[] students = new Student[6];
        students[0] = new Student("殷素素", 35, 171.5, '女');
        students[1] = new Student("杨幂", 28, 168.5, '女');
        students[2] = new Student("张无忌", 25, 181.5, '男');
        students[3] = new Student("小昭", 19, 165.5, '女');
        students[4] = new Student("赵敏", 27, 167.5, '女');
        students[5] = new Student("刘亦菲", 36, 168, '女');
        //打印数组中的数据
        for (int i = 0; i < students.length; i++) {
            Student s = students[i];
            System.out.println(s.getName() + " " + s.getAge() + " " + s.getHeight() + " " + s.getSex());
        }
        System.out.println("--------------------------------------------------------------------------------");
        //Lambda 表达式简写
        Arrays.sort(students,(Student o1, Student o2)-> {
                return o1.getAge() - o2.getAge();
            });
        //数据类型可以省略
        Arrays.sort(students,(o1,o2)-> {
            return o1.getAge() - o2.getAge();
        });
        //如果形参列表只有一个参数 ->小括号可以不写
        //如果方法体只有一行代码 那么大括号 return 分号都可以省略 若省略则同时省略
        Arrays.sort(students,(o1,o2)-> o1.getAge() - o2.getAge());





        //打印数组中的数据
        for (int i = 0; i < students.length; i++) {
            Student s = students[i];
            System.out.println(s.getName() + " " + s.getAge() + " " + s.getHeight() + " " + s.getSex());
        }
    }
}
